package com.ztom.daily.n2022.m6;

import java.util.Random;

/**
 * 在圆内随机生成点
 * <p>
 * https://leetcode.cn/problems/generate-random-point-in-a-circle/
 *
 * @author ZhangTao
 */
public class Day05Solution {

    class Solution {

        Random random;
        double xc, yc, r;

        public Solution(double radius, double x_center, double y_center) {
            random = new Random();
            xc = x_center;
            yc = y_center;
            r = radius;
        }

        public double[] randPoint() {
            while (true) {
                double x = random.nextDouble() * (2 * r) - r;
                double y = random.nextDouble() * (2 * r) - r;
                if (x * x + y * y <= r * r) {
                    return new double[]{xc + x, yc + y};
                }
            }
        }
    }
}
